package com.shangguan.atcrowdfunding.utils;

/**
 * @ClassName: Page
 * @Description: 分页
 * @Author: 一尘
 * @Date: 2020 年 01 月 16 10:09
 * @Version 1.0
 */
public class Page {
    private  Integer pageSize = 10;// 每页显示的记录数
    private Integer  startIndex;// 开始的索引值
    private  Integer totalSize;// 总记录数
    private  Integer  totalPage;// 总页数
    private  Integer  currentPage;//当前页

    public Page( Integer currentPage,Integer totalSize) {
            this.totalSize = totalSize;
        this.currentPage = currentPage;
        cacutale(currentPage,  totalSize);

    }

    //  计算分页的各个属性值
   private void cacutale(Integer currentPage, Integer totalSize){
    // 总页数
       this.totalPage = (totalSize%pageSize)==0?(totalSize/pageSize):(totalSize/pageSize+1);

    //判断当前页的值
       if(currentPage > totalPage) {
           this.currentPage = totalPage;
       }else if(currentPage < 1) {
           this.currentPage = 1;
       }else {
           this.currentPage = currentPage;
       }

       // 开始的记录数
       this.startIndex = (this.currentPage -1) * pageSize;
   }


    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    public Integer getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageSize=" + pageSize +
                ", startIndex=" + startIndex +
                ", totalSize=" + totalSize +
                ", totalPage=" + totalPage +
                ", currentPage=" + currentPage +
                '}';
    }
}
